package cn.tedu.api;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Test3_SimpleDF {
    public static void main(String[] args) throws  Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        String str = sdf.format(new Date());
        System.out.println(str);

        Date d = sdf.parse("2020-7-15");
        System.out.println(d.getMonth()+1);

        System.out.println("请输入出生日期：xx-xx-xx");
        String birthday = new Scanner(System.in).nextLine();
        //String->Date
        Date birth = sdf.parse(birthday);

        //计算天数
        long start = birth.getTime(); //出生日期 对应的毫秒值
        long now = System.currentTimeMillis(); //当前时间的毫秒值

        System.out.println((now-start)/1000/60/60/24); //ms->天
    }
}
